package com.kd.service.jobSeeker.impl;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.kd.bean.admin.AdminBasic;
import com.kd.bean.admin.AdminRec;
import com.kd.bean.jobSeeker.Report_recruitment_msg;
import com.kd.bean.jobSeeker.Report_recruitment_person;
import com.kd.dao.admin.IAdminBasicDao;
import com.kd.dao.admin.IAdminRecDao;
import com.kd.dao.jobSeeker.IReport_recruitment_personDao;
import com.kd.dao.recruiter.IRecruiter_basicDao;
import com.kd.dao.recruiter.IRecruitment_msgDao;
import com.kd.service.jobSeeker.IReport_recruitment_personService;
import com.kd.service.recruiter.IRecruitment_msgService;

/**
 * --举报招聘者（Report_recruitment_personServiceImpl）--
 * @author ZFC
 *
 */
@Service
@Transactional
public class Report_recruitment_personServiceImpl implements IReport_recruitment_personService{

	@Autowired
	private IReport_recruitment_personDao personDao;//求职者举报招聘者信息
	
	@Autowired
	private IRecruiter_basicDao basicDao;//招聘者 基本资料
	
	@Autowired
	private IRecruitment_msgDao recMsgDao;//招聘信息
	
	@Autowired
	private IAdminBasicDao adminBasicDao;//管理员相关的类 --管理员-求职者->我的消息（AdminBasic）--
	
	@Autowired
	private IAdminRecDao adminRecDao;//管理员相关的类 --管理员-招聘者->我的消息（AdminRec）--
	@Override
	public PageInfo<Report_recruitment_person> queryAllByRrp_report_state(Integer pageNum, Integer pageSize)
			throws Exception {
		PageHelper.startPage(pageNum, pageSize);
		List<Report_recruitment_person> list = personDao.queryAllByRrp_report_state();
		PageInfo<Report_recruitment_person> info = new PageInfo<>(list);
		return info;
	}

	@Override
	public Boolean updateRrp_report_state(Integer rrp_id, Integer rrp_report_state,Integer admin_id) throws Exception {
		//通过举报招聘者信息id查询举报者信息
		Report_recruitment_person recruitmentMsg = personDao.queryByRrp_id(rrp_id);
		if(rrp_report_state==2) {
			//2代表审核通过
			Integer recruiter_id = recruitmentMsg.getRecruiter_id();
			
			int i = basicDao.updateBasicState(recruiter_id, 1);//冻结招聘者  1、禁用
			if(i>0) {
				Integer[] rec_ids = recMsgDao.queryByRecruiter_id(recruiter_id);//查询所有招聘信息的id 通过关联招聘者
				if(rec_ids!=null) {
					//所有招聘者旗下的招聘信息       2、商品下架
					recMsgDao.updateRec_msg_stateByRecruiter_id(rec_ids, 2);
				}
				//管理员给求职者发送举报成功的消息
				AdminBasic adminBasic = new AdminBasic();
				adminBasic.setBasic_id(recruitmentMsg.getBasic_id());//求职者id
				adminBasic.setAdminRec_news_context("举报成功，感谢支持！！！");//消息内容
				adminBasic.setAdmin_id(admin_id);
				adminBasicDao.insertBasicJuBaoMessage(adminBasic);
				
				//管理员给招聘者发送被举报成功的消息
				AdminRec adminRec = new AdminRec();
				adminRec.setRecruiter_id(recruitmentMsg.getRecruiter_id());//招聘者id
				adminRec.setAdminRec_news_context("您以被举报，且管理员以通过，账号冻结，且旗下所有招聘信息冻结");//消息内容
				adminRec.setAdmin_id(admin_id);
				adminRecDao.insertRecJuBaoMessage(adminRec);
			}
		}else {
				//管理员给求职者发送举报失败的消息
				AdminBasic adminBasic = new AdminBasic();
				adminBasic.setBasic_id(recruitmentMsg.getBasic_id());//求职者id
				adminBasic.setAdminRec_news_context("举报失败，感谢支持！！！");//消息内容
				adminBasic.setAdmin_id(admin_id);
				adminBasicDao.insertBasicJuBaoMessage(adminBasic);
			}
		return personDao.updateRrp_report_state(rrp_id, rrp_report_state)>0;
	}

	@Override
	public Boolean insertReport_recruitment_person(Report_recruitment_person report_recruitment_person)
			throws Exception {
		
		return personDao.insertReport_recruitment_person(report_recruitment_person)>0;
	}

}
